<template>
  <el-dialog
    :title="lastGroup.flowMeterName + '详细的泵站流量计'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="dailyDialog"
  >
    <el-form
      :inline="true"
      ref="dataForm"
      :model="dataForm"
      @keyup.enter.native="getDataList()"
      class="formSearch"
    >
      <el-form-item label="日期:">
        <el-date-picker
          size="mini"
          v-model="dataForm.date"
          type="date"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button size="mini" @click="getDataList()" type="primary"
          >查询</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;"
      height="40vh"
    >
      <el-table-column
        prop="time"
        header-align="center"
        align="center"
        label="时间"
      />
      <el-table-column
        prop="value"
        header-align="center"
        align="center"
        label="爬取-瞬时流量"
      />
    </el-table>
    <el-table
      v-if="handdataList.length > 0"
      :data="handdataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;"
      height="calc(20vh - 30px)"
    >
      <el-table-column
        prop="time"
        header-align="center"
        align="center"
        label="时间"
      />
      <el-table-column
        prop="handValue"
        header-align="center"
        align="center"
        label="手抄-瞬时流量"
      />
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
import moment from "moment";

export default {
  data() {
    return {
      visible: false,
      dataListLoading: false,
      lastGroup: {},
      dataList: [],
      handdataList: [],
      dataForm: {
        id: 0,
        date: "",
        time: ""
      }
    };
  },
  methods: {
    init(dataGroup) {
      this.lastGroup = dataGroup;
      this.dataForm.id = dataGroup.id;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        this.dataListLoading = true;
        if (dataGroup.updateTime === "" || dataGroup.updateTime === null) {
          this.dataForm.date = moment(new Date()).format("YYYY-MM-DD");
        } else {
          this.dataForm.date = moment(dataGroup.updateTime).format(
            "YYYY-MM-DD"
          );
        }
        this.$http({
          url: this.$http.adornUrl("/cms/tbFlowMeter/detail"),
          method: "get",
          params: this.$http.adornParams({
            date: this.dataForm.date,
            id: this.dataForm.id
          })
        }).then(({ data }) => {
          if (data && data.code === 0) {
            //  type数据进行判断 0手抄，1调度中心爬取，2丹灶数据，3西江数据
            // 如果是0的，那么肯定有手抄数据
            this.dataList = data.vo.list; // 获取日常抄表的数据进行赋值
            this.handdataList = data.vo.handList;
          } else {
            this.dataList = [];
            this.handdataList = [];
          }
          this.dataListLoading = false;
        });
      });
    },
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/cms/tbFlowMeter/detail"),
        method: "get",
        params: this.$http.adornParams({
          date: this.dataForm.date,
          id: this.dataForm.id
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          //  type数据进行判断 0手抄，1调度中心爬取，2丹灶数据，3西江数据
          // 如果是0的，那么肯定有手抄数据
          this.dataList = data.vo.list; // 获取日常抄表的数据进行赋值
          this.handdataList = data.vo.handList;
        } else {
          this.dataList = [];
          this.handdataList = [];
        }
        this.dataListLoading = false;
      });
    }
  }
};
</script>
